package org.jb.coinche.server.rooms;

import org.jb.coinche.client.gin.RoomName;
import org.jb.coinche.client.guistatemachine.RoomService;

import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.servlet.ServletModule;

public class RoomModule extends ServletModule implements Module {

	@Override
	protected void configureServlets() {
		
		filter("*/rpc").through(RoomFilter.class);

		RoomScope scope = new RoomScope();
		bindScope(RoomScoped.class, scope );
		
		bind(RoomScope.class).toInstance(scope);
		requestInjection(scope);
		
		bind(RoomService.class).to(RoomServiceImpl.class);
	}
	
	/*
	 * 
	 */
	@Provides @RoomName
	public String provideRoomName( RoomScope scope ) {
		String roomName = scope.getCurrentRoomName();
		
		return roomName == null ? "no-room" : roomName;
	}

}
